#include <iostream>
#include <memory>

class MyClass : public std::enable_shared_from_this<MyClass>
{
public:
    std::shared_ptr<MyClass> getShared()
    {
        return shared_from_this();
    }
};

int main()
{
    std::shared_ptr<MyClass> obj1 = std::make_shared<MyClass>();
    std::shared_ptr<MyClass> obj2 = obj1->getShared();
    std::shared_ptr<MyClass> obj3 = obj1->getShared();
    std::cout << "obj1 use count: " << obj1.use_count() << std::endl;  
    std::cout << "obj2 use count: " << obj2.use_count() << std::endl;  
    std::cout << "obj2 use count: " << obj3.use_count() << std::endl;  
    return 0;
}